<?php
/**
 * 优惠券
 */

namespace app\frontend\controllers\coupon;


use App\common\components\BaseController;
use App\frontend\services\coupon\CouponServices;
use App\frontend\models\couponModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class CouponController extends BaseController
{

    public function index()
    {
        $data = [];
        return successJson('ok', $data);
    }


    /**
     * 领券中心---优惠券列表
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function lists(Request $request)
    {
        $data = $request->all();

        //
        $list = CouponServices::getCouponList($data);
        return successJson('获取成功!', $list);
    }

    public function detail(Request $request)
    {
        $data = $request->all();
        $validator = Validator::make(
            $data,
            CouponModel::update_rules(),
            CouponModel::message()
        );
        if ($validator->fails()) {
            $msg = $validator->errors()->all();
            return errorJson($msg[0], []);
        }

        $list = CouponServices::getCouponDetail($data);
        return successJson('操作成功！', $list);
    }

}

